<!-- 
  @name: 收藏的站点
  @date: 2020.1.9
 -->
<template>
	<view class="content">
		<view class="fs-list" v-if="lists.length > 0">
			<view
				class="card"
				v-for="(item, index) in lists"
				:key="item.siteId">
				<view class="msg">
					<view class="name text_over" @tap="$navigateTo('/pagesUc/site/index?siteId=' + item.siteId)">{{item.siteName}}</view>
					<view class="brand text_over" @tap="$navigateTo('/pagesUc/site/index?siteId=' + item.siteId)">尿素品牌：{{item.siteBrand}}</view>
					<view class="more">
						<view class="icon-1" @tap="$callTel(item.contactPhone)"></view>
						<text class="text">{{item.contactPhone}}</text>
						<view class="icon-2" style="margin-left: 50rpx;" @tap="isFav(item, index)"></view>
						<text class="text">已收藏</text>
					</view>
				</view>
				<view class="nav">
					<view class="navi" @tap="$navStart(item.latitude, item.longitude)"></view>
					<view class="navt">{{item.distance}}KM</view>
				</view>
			</view>
			<!-- 底部加载提示 -->
			<btm-load></btm-load>
		</view>
		
		<!-- 无收藏时 -->
		<view class="no_lists" v-if="lists.length === 0">
			<image src="../static/wxImage/bg-noSite.png" mode="aspectFill"></image>
			<text class="tip">暂无收藏内容</text>
		</view>
		
		<!-- 登录提示 -->
		<sign-in @submit="getList"></sign-in>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				lists: [],  //加注站列表
			}
		},
		onLoad() {
			this.getList();
		},
		onPullDownRefresh() {
			this.getList();
		},
		methods: {
			//取消收藏
			isFav(item, index) {
				uni.showModal({
				    content: '是否取消收藏这个加注站？',
				    success: (rs) => {
				        if (rs.confirm) {
							this.$http({
								url: this.$api.userUrl + 'addorcancelfavoritesite',
								data: {
									siteId: item.siteId,
									action: 0
								}
							}).then(res => {
								this.$successToast('已取消收藏');
								this.lists.splice(index, 1);
							});
				        }
				    }
				});
			},
			//获取加注站
			getList() {
				this.$http({
					url: this.$api.userUrl + 'getfavoritesitepage'
				}).then(res => {
					let arr = res;
					arr.forEach((item, index) => {
						item.latitude = parseFloat(item.siteLat);
						item.longitude = parseFloat(item.siteLng);
						item.distance = this.$mapDistance(
							item.latitude,
							item.longitude,
							this.$store.state.location.latitude,
							this.$store.state.location.longitude
						);
					});
					this.lists = [];
					this.lists = this.lists.concat(arr);
				});
			}
		}
	}
</script>

<style lang="scss">
	.fs-list {
		width: 750rpx;
		padding: 0 30rpx;
	}
	/* 站点card */
	.card {
		width: 100%;
		margin-top: 24rpx;
		padding: 30rpx;
		border-radius: $border-radius-bm;
		box-shadow: $box-shadow;
		background-color: $color-white;
		display: flex;
		flex-direction: row;
		.msg {
			flex: 1;
			display: inline-block;
			padding-right: 20rpx;
		}
		.name {
			font-size: 30rpx;
			font-weight: bold;
		}
		.brand {
			color: #4D4D4D;
			margin-top: 22rpx;
		}
		.more {
			margin-top: 22rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			.icon-1,
			.icon-2 {
				width: 32rpx;
				height: 32rpx;
			}
			.icon-1 {
				background-image: url('http://img.etubang.com/group1/M00/00/3F/rBCky14UAQWAJ_C7AAADzUD-bNE403.png');
			}
			.icon-2 {
				background-image: url('http://img.etubang.com/group1/M00/00/3F/rBCky14UAROAAuuQAAAEV5bxtYU582.png');
			}
			.text {
				margin-left: 16rpx;
				color: $color-grey-dark;
				font-size: 24rpx;
			}
		}
		.nav {
			text-align: center;
			padding-top: 15rpx;
		}
		.navi {
			width: 86rpx;
			height: 86rpx;
			background-image: url('http://img.etubang.com/group1/M00/00/3F/rBCky14UASqAH_25AAAOm9xqXI8646.png');
		}
		.navt {
			font-family: $font-family-num;
			font-size: 26rpx;
			color: $color-grey-dark;
			margin-top: 10rpx;
		}
	}
	
	/* 无收藏时 */
	.no_lists {
		padding-top: 400rpx;
		image {
			width: 585rpx;
			height: 308rpx;
		}
	}
</style>
